<?php

require_once("./Model/Username.php");
require_once("./Model/Password.php");
require_once("./Model/DALBase.php");

class RegisterController {
	
	/**
	 * @var NavigationView
	 */
	private $navView;
	/**
	 * @var RegisterView
	 */
	private $regView;
	/**
	 * @var DALBase
	 */
	private $DALBase;
	
	/**
	 * @var NavigationView 	$navView
	 * @var RegisterView	$regView
	 * @var DALBase			$DALBase
	 */
	public function __construct(NavigationView  $navView,
								RegisterView	$regView,
								DALBase			$DALBase) {
		$this->navView = $navView;
		$this->regView = $regView;
		$this->DALBase = $DALBase;
	}
	
	/**
	 * @var Username $username
	 * @var Password $password
	 */
	public function handleInput() {
		if ($this->regView->isRegisteringUser()) {		
			try {
				$username = new Username($this->regView->getUsername());
				$password = new Password($this->regView->getPassword());

				$this->DALBase->createUser($username, $password);
				$this->regView->registerOK();
			}
			catch (\Exception $e){
				$this->regView->setMessage($e->getMessage());
			}
		}
	}
}